<template>
  <view class="whole">
    <view class="type">
      <view class="toptype">
        <view
          :class="typeid === '' ? 'typenow' : 'typefuture'"
          @click="switchtype('')"
        >
          全部
        </view>
        <view class="division"></view>
        <view
          :class="typeid === 0 ? 'typenow' : 'typefuture'"
          @click="switchtype(0)"
        >
          收入
        </view>
        <view class="division"></view>
        <view
          :class="typeid == 1 ? 'typenow' : 'typefuture'"
          @click="switchtype(1)"
        >
          支出
        </view>
        <view class="division"></view>
        <view
          class="big"
          :class="typeid == 2 ? 'typenow' : 'typefuture'"
          @click="switchtype(2)"
        >
          挂售手续费收入
        </view>
      </view>
    </view>
    <view class="transferAll">
      <view class="" v-if="list">
        <block v-for="(item, index) in list" :key="index">
          <view class="list_whole">
            <view class="list_time">
              <!-- <text v-if="item.is_payout == 0">收入</text> -->
              <!-- <text v-if="item.is_payout == 1">提现</text> -->

              <view v-if="item.is_payout == 0" class="list_wrapper">
                <text v-if="item.type == 1">卖出</text>
                <text v-else-if="item.type == 2">提现支出</text>
                <text v-else-if="item.type == 3">购买</text>
                <!-- <text v-if="item.type == 4">后台充值</text> -->
                <text v-if class="list_remark">{{ item.remark }}</text>
              </view>
              <view v-else-if="item.is_payout == 1" class="list_wrapper">
                <text v-if="item.type == 1">卖出</text>
                <text v-else-if="item.type == 2">提现支出</text>
                <text v-else-if="item.type == 3">购买</text>
                <!-- <text v-if="item.type == 4">后台充值</text> -->
                <text v-if class="list_remark">{{ item.remark }}</text>
              </view>
              <text class="created_time">{{ item.created_at }}</text>
            </view>
            <!-- <view class="list_time" v-if="typeid == 0">
              <text v-if="item.is_payout == 0">收入</text>
              <text v-if="item.is_payout == 1">卖出</text>
              <text>{{ item.created_at }}</text>
            </view> -->
            <!-- <view class="list_time" v-if="typeid == 1">
              <text v-if="item.is_payout == 1">提现</text>
              <text>{{ item.created_at }}</text>
            </view> -->
            <view class="list_money">
              <text
                v-if="Number(item.after_balance) > Number(item.before_balance)"
                >+</text
              >
              <text v-else>-</text>
              <text>￥{{ item.money }}</text>
            </view>
          </view>
        </block>
      </view>
    </view>
    <empty :show.sync="pagestate"></empty>
  </view>
</template>

<script>
import api from "../../api/api";
import empty from "@/components/empty/empty";
export default {
  data() {
    return {
      list: [],
      pagestate: false,
      liststate: false,
      page: 1,
      typeid: "",
    };
  },
  onLoad() {},
  onShow() {
    this.record();
  },
  onReachBottom() {
    this.page++;
    this.record();
  },
  onPullDownRefresh() {
    this.page = 1;
    this.record();
  },
  methods: {
    switchtype(id) {
      this.typeid = id;
      this.page = 1;
      this.record();
    },
    async record() {
      this.pagestate = false;
      let res = await api.incomeDetails({
        query: {
          page: this.page,
          is_pay_out: this.typeid == 2 ? "" : this.typeid,
          type: this.typeid == 2 ? 4 : "",
          wallet_type: 1,
        },
        method: "POST",
        loading: "加载中",
      });
      if (res.code == 0) {
        uni.stopPullDownRefresh();
        if (this.page == 1) {
          this.list = res.data;
          if (res.data.length == 0) {
            this.pagestate = true;
          }
        } else {
          if (res.data.length > 0) {
            this.list = [...this.list, ...res.data];
          }
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.whole {
  width: 100%;
  height: 100%;
  background-color: $bg-color1;
  min-height: 100vh;
  .type {
    padding: 3rpx;
  }
  .toptype {
    // border-radius: 8px;
    background-color: $bg-color3;
    height: 100rpx;
    // margin: 30rpx 30rpx 0;
    display: flex;
    justify-content: center;
    line-height: 88rpx;
    align-content: center;

    margin: 0 auto;
    width: 690rpx;
    height: 88rpx;
    background: #292b2b;
    border-radius: 16rpx;
    .division {
      width: 4rpx;
      height: 19rpx;
      background: #313535;
      margin-top: 34rpx;
    }
    .typenow {
      flex: 1;
      font-size: 28rpx;
      font-weight: 600;
      color: $text-color3;
      // margin: 0 85rpx;
      text-align: center;
      transition: color 1s;
    }
    .typefuture {
      flex: 1;
      font-size: 28rpx;
      font-weight: 500;
      color: #ffffff;
      text-align: center;
      // margin: 0 85rpx;
    }
    .big {
      flex: 2;
    }
  }
  .transferAll {
    width: 100%;
    padding: 3rpx 0;
    border-radius: 15rpx;
    .list_whole {
      height: 140rpx;
      // margin: 30rpx 0;
      padding: 0 30rpx;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-content: center;
      border-bottom: 2rpx solid #292b2b;
      background: $bg-color1;
      .list_time {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin: 30rpx 0;
        .list_wrapper {
          display: flex;
          align-items: center;
        }
        text:nth-child(1) {
          display: inline-block;
          font-size: 16px;
          color: #ffffff;
        }
        .list_remark {
          display: inline-block;
          width: 400rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: 16px;
          color: #ffffff;
        }
        .created_time {
          font-size: 12px;
          color: #bbbbbe;
        }
      }
      .list_money {
        color: #ffffff;
        text {
          font-size: 18px;
          font-weight: 600;
          line-height: 140rpx;
        }
      }
    }
    .list_whole:not(:first-child) {
      // border-top: 2rpx solid #f6f8fa;
    }
  }
}
</style>
